home *** CD-ROM | disk | FTP | other *** search
/ Developer CD Series 2000 November: Tool Chest / Dev.CD Nov 00 TC Disk 2.toast / pc / sample code / platforms and tools / project builder / sonofsillyballs / sillyballview.h < prev    next >
Encoding:
Text File  |  2000-10-06  |  4.3 KB  |  116 lines

  1. /*
  2.     File:       SillyBallView.h
  3.  
  4.     Contains:   View class for drawing lots of silly balls.
  5.  
  6.     Written by: Quinn "The Eskimo!"
  7.  
  8.     Created:    Thu 05-Jun-1997
  9.  
  10.     Copyright:  (c)1997 by Apple Computer, Inc., all rights reserved.
  11.  
  12.     Change History (most recent first):
  13.                     7/5/00    KG    updated to Project Builder on DP4
  14.  
  15.     You may incorporate this sample code into your applications without
  16.     restriction, though the sample code has been provided "AS IS" and the
  17.     responsibility for its operation is 100% yours.  However, what you are
  18.     not permitted to do is to redistribute the source as "DSC Sample Code"
  19.     after having made changes. If you're going to re-distribute the source,
  20.     we require that you make it clear in the source that the code was
  21.     descended from Apple Sample Code, but that you've made changes.
  22. */
  23.  
  24. #import <AppKit/AppKit.h>
  25.  
  26. @interface SillyBallView : NSView
  27. {
  28.     // The following are connected up with Interface Builder.
  29.     
  30.     NSMenuItem* startStopMenuItem;        // Start/Stop menu item
  31.     NSSlider *sliderView;            // ball rate slider
  32.     NSTextField *textView;            // ball rate text view
  33.  
  34.     // The followintg are set up in our initWithFrame:
  35.     
  36.     BOOL running;                // whether we're currently drawing
  37.     NSString *textString;            // text we're drawing
  38.     NSSize textSize;                // size of the above, cached so we don't recalc it each time
  39.     NSTimer *repeatTimer;            // timer that controls how often we draw a ball
  40.     NSTimeInterval repeatPeriod;        // most recent value of the ball rate slider
  41. }
  42.  
  43. // Standard NSView methods
  44.  
  45. - (id)initWithFrame:(NSRect)frameRect;
  46.     // Standard init method, which sets up our instance
  47.     // variables and starts the timer that causes the
  48.     // ball drawing.
  49.  
  50. - (void)dealloc;
  51.     // We override dealloc to clean up repeatTimer.
  52.  
  53. - (void)drawRect:(NSRect)rect;
  54.     // NSView's are expected to override this method to do
  55.     // their drawing.  We actually do nothing in this method,
  56.     // because we don't have any persistent state.  All our drawing
  57.     // is done in response to repeatTimer firing.  See the
  58.     // explanation of this in ReadMe.rtf.
  59.  
  60. // Methods for drawing a single ball
  61.  
  62. - (void)drawRandomBallInside:(const NSRect *)rect;
  63.     // Draws Silly Ball(tm) at random coordinates within
  64.     // rect.  This method can assume we're in a state ready
  65.     // to draw, either inside the view's drawRect routine,
  66.     // or otherwise having the focus locked on this view.
  67.  
  68. - (void)drawAnother:(id)timer;
  69.     // This method is called in response to repeatTimer
  70.     // firing.  It's function is to lock focus on the view
  71.     // and then call drawRandomBallInside.
  72.  
  73. // Internal routines for changing the ball drawing
  74.  
  75. - (void)setTimerRunning:(BOOL)run source:(id)source;
  76.     // This routine starts or stops the timer based
  77.     // on the value of run.  source is the user interface
  78.     // element that caused the action; it is used to
  79.     // prevent double setting of user interface elements
  80.     // whose values have already changed.  Pass nil
  81.     // if you don't have anything obvious to pass here.
  82.  
  83. - (void)setTimerPeriod:(float)repPeriod source:(id)source;
  84.     // This routine changes the period of the timer based
  85.     // on the value of repPeriod.  repPeriod is assumed
  86.     // to be the value of the ball rate slider, ie 0 to
  87.     // 5, and is scaled appropriately to a real timer
  88.     // frequency.  source is the user interface
  89.     // element that caused the action; it is used to
  90.     // prevent double setting of user interface elements
  91.     // whose values have already changed.  Pass nil
  92.     // if you don't have anything obvious to pass here.
  93.  
  94. // Interface Builder actions
  95.  
  96. - (void)forceRedraw:(id)source;
  97.     // The purpose of this action is to clear out all the
  98.     // silly balls in the view so you can see the balls
  99.     // draw.  The action is wired to the "Clear" menu
  100.     // command.
  101.  
  102. - (void)startOrStop:(id)source;
  103.     // The purpose of this action is to either start or
  104.     // stop the drawing of balls.  Internally, it calls
  105.     // straight through to setTimerRunning:source:.
  106.     // The action is wired to the "Start"/"Stop" menu
  107.     // command.
  108.  
  109. - (void)setPeriod:(id)source;
  110.     // THe purpose of this action is to set the period
  111.     // at which the balls draw.  Internally it calls
  112.     // setTimerPeriod:source:.  It's wired to the
  113.     // Ball Rate slider.
  114.  
  115. @end
  116.